home *** CD-ROM | disk | FTP | other *** search
/ User's Choice Windows CD / User's Choice Windows CD (CMS Software)(1993).iso / misc1 / iv26_w30.zip / EXAMPLES / IDRAW / HIGHLIGH.C < prev    next >
C/C++ Source or Header  |  1980-01-05  |  4KB  |  119 lines

  1. /*
  2.  * Copyright (c) 1987, 1988, 1989 Stanford University
  3.  *
  4.  * Permission to use, copy, modify, distribute, and sell this software and its
  5.  * documentation for any purpose is hereby granted without fee, provided
  6.  * that the above copyright notice appear in all copies and that both that
  7.  * copyright notice and this permission notice appear in supporting
  8.  * documentation, and that the name of Stanford not be used in advertising or
  9.  * publicity pertaining to distribution of the software without specific,
  10.  * written prior permission.  Stanford makes no representations about
  11.  * the suitability of this software for any purpose.  It is provided "as is"
  12.  * without express or implied warranty.
  13.  *
  14.  * STANFORD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  15.  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
  16.  * IN NO EVENT SHALL STANFORD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  17.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  18.  * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  19.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  20.  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  21.  */
  22.  
  23. // $Header: highlighter.c,v 1.11 89/10/09 14:48:02 linton Exp $
  24. // implements classes HighlighterParent and Highlighter.
  25.  
  26. #include "highlighter.h"
  27. #include <InterViews/painter.h>
  28.  
  29. // HighlighterParent starts with no highlight painter.
  30.  
  31. HighlighterParent::HighlighterParent () {
  32.     highlight = nil;
  33. }
  34.  
  35. // Free storage allocated for the highlight painter.
  36.  
  37. HighlighterParent::~HighlighterParent () {
  38.     Unref(highlight);
  39. }
  40.  
  41. // SameOutputAs compares the given painter to our output painter so
  42. // our interior Highlighters can decide if they can share our
  43. // highlight painter.
  44.  
  45. boolean HighlighterParent::SameOutputAs (Painter* out) {
  46.     return out == output;
  47. }
  48.  
  49. // GetHighlightPainter creates our highlight painter if we don't have
  50. // one yet and returns it so all of our interior Highlighters can
  51. // share it as well as our output painter which they inherit
  52. // automatically.  We can't just create highlight in Reconfig because
  53. // our interior Highlighters execute their Reconfig before we do, so
  54. // we create it here (once) when they call us from their Reconfig.
  55.  
  56. Painter* HighlighterParent::GetHighlightPainter () {
  57.     if (highlight == nil) {
  58.     highlight = new Painter(output);
  59.     highlight->Reference();
  60.     highlight->SetColors(output->GetBgColor(), output->GetFgColor());
  61.     }
  62.     return highlight;
  63. }
  64.  
  65. // Highlighter starts off unhighlighted with no HighlighterParent yet.
  66.  
  67. Highlighter::Highlighter () {
  68.     hparent = nil;
  69.     highlighted = false;
  70.     highlight = nil;
  71.     normal = nil;
  72. }
  73.  
  74. // Free storage allocated for the highlight painter.
  75.  
  76. Highlighter::~Highlighter () {
  77.     output = normal;
  78.     Unref(highlight);
  79. }
  80.  
  81. // SetHighlighterParent gives us a HighlighterParent.
  82.  
  83. void Highlighter::SetHighlighterParent (HighlighterParent* hp) {
  84.     hparent = hp;
  85. }
  86.  
  87. // Highlight exchanges our painter and draws us unless we
  88. // don't have a canvas so a panel can highlight us before the panel's
  89. // inserted and a menu can unhighlight us after the menu's removed.
  90.  
  91. void Highlighter::Highlight (boolean on) {
  92.     highlighted = on;
  93.     output = on ? highlight : normal;
  94.     if (canvas != nil) {
  95.     Redraw(0, 0, xmax, ymax);
  96.     }
  97. }
  98.  
  99. // Reconfig initializes our highlight painter if necessary by getting
  100. // it from our HighlighterParent if possible or else creating a new
  101. // painter.  Then Reconfig switches to the appropriate painter.
  102.  
  103. void Highlighter::Reconfig () {
  104.     Interactor::Reconfig();
  105.     if (output != highlight && output != normal) {
  106.     Unref(highlight);
  107.     if (hparent != nil && hparent->SameOutputAs(output)) {
  108.         highlight = hparent->GetHighlightPainter();
  109.         highlight->Reference();
  110.     } else {        // bite the bullet
  111.         highlight = new Painter(output);
  112.         highlight->Reference();
  113.         highlight->SetColors(output->GetBgColor(), output->GetFgColor());
  114.     }
  115.     normal = output;
  116.     }
  117.     output = highlighted ? highlight : normal;
  118. }
  119.